package com.zzyl.nursing.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.DateUtils;
import com.zzyl.common.utils.StringUtils;
import com.zzyl.nursing.dto.ElderParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.ElderMapper;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.service.IElderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;

/**
 * elderService业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-23
 */
@Service
public class ElderServiceImpl extends ServiceImpl<ElderMapper, Elder> implements IElderService
{
    @Autowired
    private ElderMapper elderMapper;

    /**
     * 查询elder
     * 
     * @param id elder主键
     * @return elder
     */
    @Override
    public Elder selectElderById(Long id)
    {
        return getById(id);
    }

    /**
     * 查询elder列表
     * 
     * @param elder elder
     * @return elder
     */
    @Override
    public List<Elder> selectElderList(Elder elder)
    {
        return elderMapper.selectElderList(elder);
    }

    /**
     * 新增elder
     * 
     * @param elder elder
     * @return 结果
     */
    @Override
    public int insertElder(Elder elder)
    {
        return save(elder) ? 1 : 0;
    }

    /**
     * 修改elder
     * 
     * @param elder elder
     * @return 结果
     */
    @Override
    public int updateElder(Elder elder)
    {
        return updateById(elder) ? 1 : 0;
    }

    /**
     * 批量删除elder
     * 
     * @param ids 需要删除的elder主键
     * @return 结果
     */
    @Override
    public int deleteElderByIds(Long[] ids)
    {
        return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除elder信息
     * 
     * @param id elder主键
     * @return 结果
     */
    @Override
    public int deleteElderById(Long id)
    {
        return removeById(id) ? 1 : 0;
    }

    /**
     * 查询已经入住的老人列表
     *
     * @param dto
     * @return
     */
    @Override
    public TableDataInfo<Elder> pageQuery(ElderParamDto dto) {
        Page<Elder> page = Page.of(dto.getPageNum(), dto.getPageSize());
        lambdaQuery().eq(dto.getStatus()!=null, Elder::getStatus, dto.getStatus())
                .like(StringUtils.hasText(dto.getName()), Elder::getName, dto.getName())
                .like(StringUtils.hasText(dto.getIdCardNo()), Elder::getIdCardNo, dto.getIdCardNo())
                .select(Elder::getId, Elder::getName, Elder::getIdCardNo, Elder::getBedNumber)
                .page(page);
        TableDataInfo<Elder> voList = new TableDataInfo<>(page.getRecords(), (int) page.getTotal());
        voList.setMsg("请求成功");
        voList.setCode(200);
        return voList;
    }
}
